package sanlie1;

public class hash1 {
    private int count=0;
    final int Max=12;
    final int IN=0;
    protected hashlink[] a=new hashlink[Max];

    public hash1(){
        for(int i=0;i<Max;i++){
            a[i].num=IN;
        }
    }

    public hash1(hashlink[] key){
        for(int i=0;i<Max;i++){
            a[i].setNumber(IN);
        }
        for(int j=0;j<a.length;j++){
            Insert(key[j].num);
        }
    }

    public void Insert(int key){
        int addr=hash(key);
        while(a[addr].num!=IN){
            a[addr]=a[addr].next;
            a[addr].num=key;
        }
        a[addr].num=key;
        count++;
    }

    public int hash(int key){
        return key%Max;
    }

    public boolean search(int b){
        int liandizhi = hash(b);
        while(a[liandizhi].num != b) {
            liandizhi = hash(liandizhi + 1);
            if(a[liandizhi].num == IN || liandizhi == hash(b)) {
                return false;
            }
        }
        return true;
    }
}
